package com.example.cardgame_1

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    // 声明控件变量
    private lateinit var studentIdEt: EditText
    private lateinit var nameEt: EditText
    private lateinit var genderEt: EditText
    private lateinit var phoneEt: EditText
    private lateinit var emailEt: EditText
    private lateinit var confirmBtn: Button
    private lateinit var modifyBtn: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        // 初始化控件
        initViews()

        // 确认按钮点击事件：传递数据到SecondActivity
        confirmBtn.setOnClickListener {
            val studentId = studentIdEt.text.toString()
            val name = nameEt.text.toString()
            val gender = genderEt.text.toString()
            val phone = phoneEt.text.toString()
            val email = emailEt.text.toString()

            // 跳转到SecondActivity并传递数据
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra("STUDENT_ID", studentId)
            intent.putExtra("NAME", name)
            intent.putExtra("GENDER", gender)
            intent.putExtra("PHONE", phone)
            intent.putExtra("EMAIL", email)
            startActivity(intent)
        }

        // 修改按钮点击事件（当前页面即为输入页，可留空或提示）
        modifyBtn.setOnClickListener {
            // 清空输入框示例
            studentIdEt.text.clear()
            nameEt.text.clear()
            genderEt.text.clear()
            phoneEt.text.clear()
            emailEt.text.clear()
        }

        // 处理系统栏Insets
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }

    // 初始化所有控件
    private fun initViews() {
        studentIdEt = findViewById(R.id.student_id)
        nameEt = findViewById(R.id.name)
        genderEt = findViewById(R.id.gender)
        phoneEt = findViewById(R.id.phone)
        emailEt = findViewById(R.id.email)
        confirmBtn = findViewById(R.id.confirm)
        modifyBtn = findViewById(R.id.modify)
    }
}